class Solution
{
public:
    string countAndSay(int n)
    {
        if (n == 1)
        {
            return "1";
        }
        else
        {
            return countAndSay(countAndSay(n - 1));
        }
    }
    string countAndSay(const string &s)
    {
        int lastCount = 1;
        int n = s.size();
        string answer;
        for (int i = 1; i < n; ++i)
        {
            if (s[i] == s[i - 1])
            {
                ++lastCount;
            }
            else
            {
                answer += to_string(lastCount);
                answer += s[i - 1];
                lastCount = 1;
            }
        }
        answer += to_string(lastCount);
        answer += s[n - 1];
        return answer;
    }
};